var settings = {
	color: 'black',
	opacity: 1,
	lineWidth: 3
};

settings.toPen = function() {
	return new Pen(this.color, this.lineWidth, this.opacity);
}


var initCanvas = function() {
	var canvas = document.querySelector('canvas');
	canvas.width = window.innerWidth;
	canvas.height = window.innerHeight;
};

var addEvent = function() {
	$('.pen').click(function() {
		$('.pen.btn').removeClass('btn-primary');
		$(this).addClass('btn-primary');
	});
	$('#undo').click(function() {
		pImage.undo();
	});
	$('#redo').click(function() {
		pImage.redo();
	});
	document.body.addEventListener(eventType.start, function() {
		$('.touch-hide').hide();
	}, false);
	document.body.addEventListener('touchmove', function(ev) {
		ev.preventDefault();
	}, false);
	$('.config-range input').bind(eventType.start, function(ev) {
		ev.stopPropagation();
	});
}; 

window.addEventListener('load', function() {
	initCanvas();
	var pImage = new PImage(document.querySelector('canvas'));
	window.pImage = pImage;
	addEvent();
}, false);

var saveLocalStorage = function(pImage) {
	localStorage.setItem
};

var eventType = {};

if (/mobile/i.test(navigator.userAgent)) {
	eventType = {
		start: 'touchstart',
		move: 'touchmove',
		end: 'touchend'
	};
} else {
	eventType = {
		start: 'mousedown',
		move: 'mousemove',
		end: 'mouseup'
	};
}